﻿using Sprout.Schedule.Dtos;
using Sprout.Schedule.Enums;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Sprout.Schedule.Interfaces
{
    public interface ITaskService
    {
        /// <summary>
        /// 新增任务
        /// </summary>
        /// <param name="dto"></param>
        /// <returns>主键ID</returns>
        Task<long> Insert(TaskInfo dto);

        /// <summary>
        /// 删除任务
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task Delete(long id);

        /// <summary>
        /// 查询详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<TaskInfo> GetDetailAsync(long id);

        /// <summary>
        /// 查询任务列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        Task<IList<TaskInfo>> Gets(TaskQuery query);

        /// <summary>
        /// 修改任务
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        Task Update(TaskInfo dto);

        /// <summary>
        /// 修改任务状态
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="status">状态</param>
        /// <returns></returns>
        Task UpdateStatus(long id, TaskStatusEnum status);

        /// <summary>
        /// 任务开始运行
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task RunAsync(long id);

        /// <summary>
        /// 任务运行结束
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task RunEndAsync(long id);

        /// <summary>
        /// 修改最后执行的值
        /// </summary>
        /// <param name="id"></param>
        /// <param name="runValue"></param>
        /// <returns></returns>
        Task UpdateRunValueAsync(long id, string runValue);

        /// <summary>
        /// 中止任务
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task Interrupt(long id);

        /// <summary>
        /// 任务开始运行
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        void Run(long id);

        /// <summary>
        /// 任务运行结束
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        void RunEnd(long id);

        /// <summary>
        /// 修改最后执行的值
        /// </summary>
        /// <param name="id"></param>
        /// <param name="runValue"></param>
        /// <returns></returns>
        void UpdateRunValue(long id, string runValue);

        /// <summary>
        /// 查询详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        TaskInfo GetDetail(long id);
    }
}
